package com.s59.demo.service.impl;

import com.s59.demo.entity.User;
import com.s59.demo.mapper.UserMapper;
import com.s59.demo.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.io.Serializable;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author baomidou
 * @since 2023-05-08
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
    @Cacheable(cacheNames = "s59",key = "'UserServiceImpl.getById.'+#id")
    @Override
    public User getById(Serializable id) {
        System.out.println("id="+id);
        return super.getById(id);
    }

    @CachePut(cacheNames = "s59",key = "'UserServiceImpl.getById.'+#entity.id")
    @Override
    public boolean save(User entity) {
        return super.save(entity);
    }

    @CacheEvict(cacheNames = "s59",key = "'UserServiceImpl.getById.'+#entity.id")
    @Override
    public boolean removeById(User entity) {
        return super.removeById(entity);
    }

    @CachePut(cacheNames = "s59",key = "'UserServiceImpl.getById.'+#user.id")
    @Override
    public User updateByIdWithCache(User user) {
        super.updateById(user);
        return user;
    }

    @CachePut(cacheNames = "s59",key = "'UserServiceImpl.getById.'+#user.id")
    @Override
    public User saveWithCache(User user) {
        super.save(user);
        return user;
    }
}
